import { createRouter, createWebHistory } from 'vue-router'

const token = localStorage.getItem('token')

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'steer',
      component: () => import('../views/steer/guideView.vue')
    },
    {
      path: '/layout',
      name: 'home',
      redirect: '/home',
      component: () => import('../views/layout/layoutIndex.vue'),
      children: [
        {
          path: '/home',
          meta: {
            title: '首页'
          },
          component: () => import('../views/home/homeIndex.vue')
        },
        {
          path: '/message',
          meta: {
            title: '消息'
          },
          component: () => import('../views/message/msgIndex.vue')
        },
        {
          path: '/shop',
          meta: {
            title: '商城'
          },
          component: () => import('../views/shop/shopIndex.vue')
        },
        {
          path: '/case',
          meta: {
            title: '患者案例'
          },
          component: () => import('../views/case/caseIndex.vue')
        },
        {
          path: '/mine',
          meta: {
            title: '我的'
          },
          component: () => import('../views/mine/mineIndex.vue')
        },

      ]
    },
    {
      path: '/detail',
      meta: {
        title: '详情'
      },
      component: () => import('../views/detail/index.vue')
    },
    // 设置
    {
      path: '/emit',
      name: 'emit',
      component: () => import('../views/emit/emitInde.vue')
    },
    // 登录
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/login/loginIndex.vue')
    },
    // 修改昵称
    {
      path: '/emit-emit',
      name: 'emit-emit',
      component: () => import('../views/emit-emit/emittIndex.vue')
    },
    // 在线问诊
    {
      path: '/zxwz',
      name: 'zxwz',
      component: () => import('../views/box/zxwz/zxwzIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      }
    },
    // 健康档案
    {
      path: '/jkda',
      name: 'jkda',
      component: () => import('../views/box/jkda/jkdaIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      }
    },
    // 新建档案
    {
      path:'/xjda',
      name:'xjda',
      component:()=>import('../views/box/xjda/xjdaIndex.vue')
    },
    // 用药建议
    {
      path: '/yyjy',
      name: 'yyjy',
      component: () => import('../views/box/yyjy/yyjyIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      }
    },
    // 优选订单
    {
      path: '/yxdd',
      name: 'yxdd',
      component: () => import('../views/box/yxdd/yxddIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      }
    },
    // 我的医生
    {
      path: '/wdys',
      name: 'wdys',
      component: () => import('../views/box/wdys/wdysIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      }
    },
    // 随访计划
    {
      path: '/sfjh',
      name: 'sfjh',
      component: () => import('../views/box/sfjh/sfjhIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      }
    },
    // 我的订单
    {
      path: '/myshop',
      name: 'myshop',
      component: () => import('../views/boxs/myshop/myshopIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      }
    },
    // 挂号订单
    {
      path: '/order',
      name: 'order',
      component: () => import('../views/boxs/order/orderIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      }
    },
    // 收货地址
    {
      path: '/address',
      name: 'address',
      component: () => import('../views/boxs/address/addressIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      }
    },
    // 我的卡券
    {
      path: '/mycard',
      name: 'mycard',
      component: () => import('../views/boxs/mycard/mycardIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      }
    },
    // 门诊预约
    {
      path: '/make',
      name: 'make',
      component: () => import('../views/boxs/make/makeIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      }
    },
    // 商品收藏
    {
      path: '/collection',
      name: 'collection',
      component: () => import('../views/boxs/collection/collectionIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      }
    },
    // 意见反馈
    {
      path:'/feedback',
      name:'feedback',
      component:()=>import('../views/boxs/feedback/feedbackIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      }
    },
    // 引导页
    {
      path: '/setp',
      name: 'setp',
      component: () => import('../views/step/stepIndex.vue')
    },
    // 权益中心
    {
      path: '/member',
      name: 'member',
      component: () => import('../views/member/memberIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      }
    },
    // 注册
    {
      path: '/logon',
      name: 'logon',
      component: () => import('../views/logon/logonIndex.vue')
    },
    // 引导页
    {
      path: '/guide',
      name: 'guide',
      component: () => import('../views/guide/guideIndex.vue')
    },
     {
          path: '/detail',
          meta: {
            title: '详情'
          },
          component: () => import('../views/detail/index.vue')
        },
        {
          path: '/ask',
          meta: {
            title: '详情'
          },
          component: () => import('../views/ask/askIndex.vue')
        },



         {
          path: '/dizi',
          meta: {
            title: '地址'
          },
          component: () => import('../views/dizi/index.vue')
        },
        // 首页列表详情
         {
          path: '/recdetail',
          meta: {
            title: '详情'
          },
          component: () => import('../views/recDetail/index.vue'),
          beforeEnter:(to,from,next)=>{
        if(token){
          next()
        }else{
          next('/login')
        }
      }
        },
         // 搜索历史页面
         {
          path: '/caseSearch',
          meta: {
            title: '搜索页面'
          },
          component: () => import('../views/caseSearch/index.vue')
        },
         {
          path: '/caseDetail',
          meta: {
            title: '患者案例详情'
          },
          component: () => import('../views/caseDetail/index.vue')
        },
    {
      path: '/detail',
      meta: {
        title: '详情'
      },
      component: () => import('../views/detail/index.vue')
    },
    {
      path: '/dizi',
      meta: {
        title: '地址'
      },
      component: () => import('../views/dizi/index.vue')
    },
    // 协议
    {
      path:'/agreement',
      name:'agreement',
      component:()=>import('../views/agreement/agreementIndex.vue')
    },

    {
      path:'/take',
      name:'take',
      component:()=>import('../views/take/takeIndex.vue')
    },
    {
      path:'/yuyue',
      name:'yuyue',
      component:()=>import('../views/yuyue/index.vue')
    },
    {
      path:'/city',
      name:'城市',
      component:()=>import('../views/city/index.vue')
    }, {
      path: '/live',
      meta: {
        title: '直播'
      },
      component: () => import('../views/liv/index.vue')
    },
    //直播详情
    {
      path: '/livedtl',
      meta: {
        title: '直播'
      },
      component: () => import('../views/livdta/index.vue')
    },
    //商品详情
    {
      path: '/shopdetail',
      meta: {
        title: '商品详情'
      },
      component: () => import('../views/shopdetail/index.vue')
    },

  ],
})

export default router
